<?php
	require('../../inc/config.php');
	$item_menu[0] = 'News';
	$item_menu[1] = 'campaign';

    $title = 'Crear / Editar Campaña';
	
	include('../header.php');

	if (!isset($_SESSION["admin"])) {redirect(ADMIN."login.php");	exit(); }

	if(!empty($_SESSION['Msg'])) {
	   echo mensaje_ok($_SESSION['Msg']);
		$_SESSION['Msg']='';
	}

    $de_donde     = '';

	
	$id       = request('id',0);
	$news_id  = request('news_id',0);

	$cond	= "select * from newsletter where id='$news_id' and activo='1'";
	$rs 	= $db->SelectLimit($cond);
	$News 	= $rs->FetchRow();

	$cond	= "select * from newsletter_campaign where id='$id'";
	$rs 	= $db->SelectLimit($cond);
	$data 	= $rs->FetchRow();
	$lista  = explode(',',$data['listas']);
	
	//-----------------------------------------------------------------------
	//                                                  Lista de Suscriptores	
	//-----------------------------------------------------------------------	
	$sql = "select * from listas_correos where activo='1' order by nombre asc";
	$rs  = $db->Execute($sql);
	$Listas = $rs->GetRows();
	
?>
	<h2>Crear Campaña de mailing</h2>	
	<form action='campaign.php' method='post' class="form-horizontal" role="form" style='margin:20px;'>
		<div class="form-group">
			<label class="col-md-3 control-label" for="nombre">Nombre de la Campaña:</label>
			<div class="col-md-6">
				<input type='text' id="nombre" name='data[nombre]' required value="<?php echo $data['nombre'];?>" class="form-control"/>
			</div>
		</div>
		<div class="form-group">
			<label class="col-md-3 control-label" for="titulo">Titulo del Newsletter:</label>
			<div class="col-md-6">
				<input type='hidden' name='data[newsletter_id]' value="<?php echo $News['id'];?>"/>
				<input type='text' id="titulo" value="<?php echo $News['titulo'];?>" readonly class="form-control"/>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-md-3 control-label" for="titulo">Listas de Suscriptores:</label>
			<div class="col-md-6">
				<table >
					<?php foreach($Listas as $l){?>
						<tr >
							<td style='padding:3px;'>
								<?php $sel = iif( in_array($l['id'],$lista),'checked','');?>
								<input type='checkbox' name='data[listas][<?php echo $l['id'];?>]' <?php echo $sel;?> value='<?php echo $l['id'];?>' >
							</td>
							<td style='padding:3px;'><?php echo $l['nombre'];?></td>
						</tr>
					<?php } ?>
				</table>
			</div>
		</div>

		<div class="form-group">
			<label class="col-md-3 control-label" for="titulo"></label>
			<div class="col-md-6">
				<input type='hidden' name='data[id]' value='<?php echo $data['id'];?>'>
				<input type='hidden' name='accion' value='guardar'>
				<button type='submit' class='btn btn-primary'><i class="fa fa-floppy-o"></i> Guardar Campaña</button>
			</div>
		</div>
		
		
	
	</form>
	
	
<?php	
	include(RADMIN.'/footer.php');
?>